package great.project.service;

import great.project.mapper.UserInfoMapper;
import great.project.pojo.UserInfo;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void test1() {
        userInfoMapper.insertSelective(new UserInfo(null, "方法1"));

        try {
            ((UserInfoService) AopContext.currentProxy()).test2();
        } catch (Exception e) {
            e.printStackTrace();
        }
//        int i = 9 / 0;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void test2() {
        userInfoMapper.insertSelective(new UserInfo(null, "方法2"));
        int i = 9 / 0;
    }
}
